<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card layui-hide" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <input type="hidden" id="enginid" name="enginid">
        </form>
    </div>
</div>



<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <?php include '../public/engin_dao.php' ?>
            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>




    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('电子文件(系统)');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_engin_elecfile_list),where: {}, page: true, height: '780'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);


                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field: 'name', title: '文件名'}
                ,{field: 'size', title: '文件大小'}
                ,{field: 'enginname', title: '项目名称'}
                ,{field: 'title', title: '业务类型'}
                ,{field: 'created_user_name', title: '新建人'}
                ,{field: 'created_at', title: '新建时间'}
                ,{field: 'filenav_name', title: '归档分类'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        var fileext = trData.ext;
        var filepath = trData.encpath;
        var fileurl = get_file_complete(filepath);
        if(fileext == 'png' || fileext == 'pneg' || fileext == 'jpg' || fileext == 'jpeg' || fileext == 'gif'){
            upload_files_viewer_imgnew_show(filepath, fileurl);
        }else if(fileext == 'pdf'){
            upload_files_viewer_pdf_show(fileurl);
        }else if(fileext == 'doc' || fileext == 'docx' || fileext == 'xls' || fileext == 'xlsx' || fileext == 'ppt' || fileext == 'pptx'){
            upload_files_vieweroffice_show(fileurl);
        }else{
            upload_files_show_yulan_not();
        }
    }
    function auth_but_func_gui(){
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error("请选择要操作的数据");return false;
        }
        openPageEdit('gui.php?ids='+idArr.join(','));
    }
    function auth_but_func_muldel(buttitle){
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        data_delete(ask_engin_elecfile_del, {id: idArr.join(',')});
    }
    function auth_but_func_rename(){
        var idArr = get_table_check_idarr();
        if(idArr.length != 1){
            facade.error("请选择要操作的数据(单条)");return false;
        }
        openPageEdit('rename.php?id='+idArr[0]);
    }
    function auth_but_func_muldown(buttitle){
        var enginid = $("#enginid").val() || 0;
        var idArr = get_table_check_idarr();
        if(idArr.length < 1){
            facade.error(buttitle + "：请选择数据");return false;
        }
        facade.ajax({url: ask_engin_elecfile_down, data:{enginid:enginid, ids: idArr.join(',')}}).done(function(res){
            if (res.code === 2000) {
                let btnDownload = document.createElement('a'),
                    clickEvent = document.createEvent("MouseEvent");
                let url = server_api_name + res.data;
                clickEvent.initEvent("click", true, false);
                btnDownload.setAttribute("href", url);
                btnDownload.setAttribute("target", '_blank');
                btnDownload.dispatchEvent(clickEvent);
            }
        });
    }
    function auth_but_func_down(buttitle, index){
        var enginid = $("#enginid").val() || 0;
        var trData = currTabData[index];
        facade.ajax({url: ask_engin_elecfile_down, data:{enginid:enginid, ids: trData.id}}).done(function(res){
            if (res.code === 2000) {
                let btnDownload = document.createElement('a'),
                    clickEvent = document.createEvent("MouseEvent");
                let url = server_api_name + res.data;
                clickEvent.initEvent("click", true, false);
                btnDownload.setAttribute("href", url);
                btnDownload.setAttribute("target", '_blank');
                btnDownload.dispatchEvent(clickEvent);
            }
        });
    }


</script>
</body>
</html>
